<!-- 调拨单记录 -->
<template>
  <div id="change">
    <div class="change-top">
      单据日期&nbsp;
      <el-date-picker size="small" style="width: 150px;" v-model="listDate" type="date" placeholder="选择日期">
      </el-date-picker>
      &nbsp;&nbsp;业务员&nbsp;
      <el-select size="small" style="width: 150px;">

      </el-select>

      <PublicButton />
      <PublicLink />
    </div>
    <div class=" change-content">
      <el-table @row-click="handlerClick" :row-style="{ height: '55px' }" show-summary :summary-method="getSummaries"
        height="500px" :data="tableData" border style="width: 100%;font-size: 13px;">
        <el-table-column prop="goodsId" label="商品编号" width="240">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit" v-model="scope.row.goodsId"></el-input>
            <span v-else>{{ scope.row.goodsId }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="code" label="商品类别" width="120">
        </el-table-column>
        <el-table-column prop="goodsRemark" label="商品备注" width="120">
        </el-table-column>
        <el-table-column prop="brand" label="品牌" width="120">
        </el-table-column>
        <el-table-column prop="shuxing" label="属性" width="120">
        </el-table-column>
        <el-table-column prop="unit" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="num" label="数量" width="120">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit" v-model="scope.row.num"></el-input>
            <span v-else>{{ scope.row.num }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="outWid" label="调出仓库" width="150">
          <template slot-scope="scope">
            <el-select size="small" v-if="scope.row.isEdit" v-model="scope.row.outWid"></el-select>
            <!-- <span v-else>{{ scope.row.goodsId }}</span> -->
          </template>
        </el-table-column>
        <el-table-column prop="inputWid" label="调入仓库" width="150">
          <template slot-scope="scope">
            <el-select size="small" v-if="scope.row.isEdit" v-model="scope.row.inputWid"></el-select>
            <!-- <span v-else>{{ scope.row.goodsId }}</span> -->
          </template>
        </el-table-column>
        <!-- <el-table-column prop="num" label="可用库存" width="120">
        </el-table-column> -->
        <el-table-column prop="remark" label="备注" width="120">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit" v-model="scope.row.remark"></el-input>
            <span v-else>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-button style="position: relative;right: -1200px;" @click="goto('changeList')">历史单据</el-button>
    </div>
  </div>
</template>

<script>
import PublicButton from '../public_com/PublicButton.vue';
import PublicLink from '../public_com/PublicLink.vue';

export default {
  name: 'ChangeList',
  components: {
    PublicLink,
    PublicButton
  },
  data() {
    return {//分页参数
      listDate: '',
      switchValue: '1',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: '',
      input: '',
      tableData:
        [
          {
            goodsId: '',
            code: "",
            unit: '',
            pid: '',
            mid: '',
            aid: '',
            num: '',
            outWid: '',
            inputWid: '',
            aboutCode: '',
            remark: '',
            createDate: '',
            status: '',
            state: '',
            isEdit: false
          },
          {
            goodsId: '',
            code: "",
            unit: '',
            pid: '',
            mid: '',
            aid: '',
            num: '',
            outWid: '',
            inputWid: '',
            aboutCode: '',
            remark: '',
            createDate: '',
            status: '',
            state: '',
            isEdit: false
          },
          {}
        ],
      value1: '',
    }
  },
  methods: {
    goto(to) {
      this.$router.push(to)
    },
    handlerClick(row, column, event) {
      this.tableData.forEach((store, index) => {
        store.isEdit = false
      })
      row.isEdit = true
    },

    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === "num") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        }
      });

      return sums;
    }

  }

}
</script>

<style scoped>
#change {
  width: 100%;
  height: 100%;
}

.change-top {
  width: calc(100% -20px);
  height: 60px;
  /* background-color: pink; */
  line-height: 60px;
  padding-left: 20px;
  font-size: 13px;
}

.change-content {
  width: 100%;
  height: calc(100% - 60px);
  /* background-color: skyblue; */
}

.el-input,
.el-button {
  font-size: 13px;
}

/* 合计行整体样式修改开始 */
.el-table /deep/ .el-table__footer-wrapper tbody td {
  background-color: #fff1d4;
}

.el-table /deep/ .el-table__body tr:hover>td {
  background-color: #fff1d4;
}
</style>